package org.jeecg.modules.knowledge.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.jeecg.modules.collectarticles.entity.PhilCollectionArticles;
import org.jeecg.modules.collectarticles.vo.CollectsVO;
import org.jeecg.modules.knowledge.entity.PhilKnowledge;
import org.joda.time.DateTime;

import java.util.Collection;
import java.util.List;

/**
 * @Description: 知识
 * @Author: jeecg-boot
 * @Date:   2020-12-20
 * @Version: V1.0
 */
public interface PhilKnowledgeMapper extends BaseMapper<PhilKnowledge> {

    /**
     * TODO: 更新知识的阅读量
     *
     *
     * @author ZhangHaoyu
     * @param id
     * @return void
     */
    @Update("update `phil_knowledge` set knowledge_reading_num = knowledge_reading_num+1 where id = #{id}")
    void incrReadNum(@Param("id") String id);

    /**
     * TODO:
     *
     *
     * @author ZhangHaoyu
     * @param list 关键字集合
     * @param id
     * @return void
     */
    void insertKeyword(@Param("list") List<String> list, @Param("id") String id);

    /**
     * TODO: 根据关键字获取文章列表集合
     *
     *
     * @author ZhangHaoyu
     * @param keyword
     * @return java.util.List<org.jeecg.modules.knowledge.entity.PhilKnowledge>
     */
    List<PhilKnowledge> getKnowledgeListByKeyword(@Param("keyword") String keyword);

    /**
     * TODO:根据文章id删除
     *
     *
     * @author ZhangHaoyu
     * @param id
     * @return void
     */
    @Delete("delete from knowledge_keyword where knowledge_id = #{id}")
    void delKeywordKnowledge(@Param("id") String id);

    /**
     * TODO:
     *
     *
     * @author ZhangHaoyu
     * @param monday
     * @param sunday
     * @return int
     */
    @Select("select count(id) from phil_knowledge where create_time between #{monday} and #{sunday}")
    int count(@Param("monday") DateTime monday, @Param("sunday") DateTime sunday);

    /**
     * TODO:
     *
     *
     * @author ZhangHaoyu
     * @param page
     * @param philCollectionKnowledges
     * @return List<CollectsVO>
     */
    List<CollectsVO> queryArticleCollectByIds(@Param("list") List<PhilCollectionArticles> philCollectionKnowledges);

    /**
     * TODO: 根据类型，分页查询知识
     *
     * @author: Zhang hao yu
     * @param page
     * @param knowledgeType
     * @return: java.util.List<org.jeecg.modules.knowledge.entity.PhilKnowledge>
     */
    @Select("select * from phil_knowledge where knowledge_type = #{knowledgeType} order by knowledge_column_top,create_time desc")
    List<PhilKnowledge> selectList2(Page<PhilKnowledge> page, @Param("knowledgeType") String knowledgeType);
}
